/**
 * 
 */
package net.mikoo.seals.common.constant;

/**
 * @author huangxm
 *
 */
public enum CodeStatus {

	SYSTEM_ERROR(-1, "系统出错"),

	SUCCESS(0, "操作成功"),

	BAD_PARAMETER(1, "错误参数请求");

	private final int value;

	private final String reasonPhrase;

	private CodeStatus(int value, String reasonPhrase) {
		this.value = value;
		this.reasonPhrase = reasonPhrase;
	}

	public int value() {
		return this.value;
	}

	public String getReasonPhrase() {
		return reasonPhrase;
	}

	public Series series() {
		return Series.valueOf(this);
	}

	@Override
	public String toString() {
		return Integer.toString(value);
	}

	public static CodeStatus valueOf(int statusCode) {
		for (CodeStatus status : values()) {
			if (status.value == statusCode) {
				return status;
			}
		}
		throw new IllegalArgumentException("No matching constant for ["
				+ statusCode + "]");
	}

	public static enum Series {

		INFORMATIONAL(1), SUCCESSFUL(2), REDIRECTION(3), CLIENT_ERROR(4), SERVER_ERROR(
				5);

		private final int value;

		private Series(int value) {
			this.value = value;
		}

		public int value() {
			return this.value;
		}

		public static Series valueOf(int status) {
			int seriesCode = status / 100;
			for (Series series : values()) {
				if (series.value == seriesCode) {
					return series;
				}
			}
			throw new IllegalArgumentException("No matching constant for ["
					+ status + "]");
		}

		public static Series valueOf(CodeStatus status) {
			return valueOf(status.value);
		}

	}

}
